package com.filldream.fastboot.common.entity.db;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.filldream.fastboot.common.constant.enums.StockMarketUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Arrays;

@Data
@TableName("stock")
public class StockBaseInfo {

	@TableId(value = "stock_id", type = IdType.AUTO)
	private Long stockId;

	@ApiModelProperty(value = "无前缀代码")
	private String stockCode;

	@ApiModelProperty(value = "名称")
	private String stockName;

	@ApiModelProperty(value = "拼音首字母缩写")
	private String spell;

	@ApiModelProperty(value = "同花市场ID")
	private String marketId;

	@ApiModelProperty(value = "东财市场ID")
	private String cfMarketId;

	@ApiModelProperty(value = "腾讯市场ID")
	private String qtMarketId;

	@ApiModelProperty(value = "市场名称")
	private String marketName;

	@ApiModelProperty(value = "搜索需要的补全代码")
	private String searchCode;

	@ApiModelProperty(value = "未知")
	private String func;

	/**
	 * 初始化搜索代码
	 * @return
	 */
	public String initSearchCode(){
		if( marketName.equals("沪A") || marketName.equals("科创") || marketId.equals("20") ){
			searchCode = "sh"+stockCode;
		}else if( marketName.equals("深A") || marketName.equals("创") || marketId.equals("36") ){
			searchCode = "sz"+stockCode;
		}else if( marketName.equals("京A") ) {
			searchCode = "bj" + stockCode;
		}else if( marketName.equals("美股") ){
			searchCode = "us"+stockCode;
		}else if( marketName.equals("英股") ){
			searchCode = "uk"+stockCode;
		}else if( marketName.equals("指数") ) {
			if (marketId.equals("176")) {
				if (Arrays.asList("恒生指数", "国企指数").contains(stockName)) {
					searchCode = "hk" + stockCode;
				} else if (stockCode.equals("HS2083")) {
					searchCode = "hkHSTECH";
				}
			}
			if (marketId.equals("88")) {
				if (Arrays.asList("标准普尔500指数").contains(stockName)) {
					searchCode = "usINX";
				} else {
					searchCode = "us" + stockCode;
				}
			}
			if (marketId.equals("144")) {
				if (stockCode.equals("899050")) {
					searchCode = "bj" + stockCode;
				}
			}

		}else if( marketId.equals("177") ){
			//HK开头的股票
			if( stockCode.startsWith("HK") ){
				//港股的补0
				searchCode = stockCode.replaceAll("HK","hk0");
			}
		}else if( marketId.equals("16") || marketId.equals("32") ){
			if (stockCode.startsWith("1A") || stockCode.startsWith("1B")) {
				searchCode = "sh" + stockCode.replaceAll("1A", "00").replaceAll("1B", "00");
			}else if( marketName.equals("沪指") ){
				searchCode = "sh"+stockCode;
			}else if( marketName.equals("深指") ){
				searchCode = "sz"+stockCode;
			}
		}

		//获取对应的东财和腾讯的市场ID
		StockMarket stockMarket = StockMarketUtil.findByThsType(marketId,stockCode);
		if( stockMarket!= null ){
			cfMarketId = stockMarket.getCfImgType();
			qtMarketId = stockMarket.getTxType();
		}
		return searchCode;
	}

}
